/*
 * Copyright 2008 Nathan C Jones
 * 
 * This file is part of Fivehundred.
 * 
 * Fivehundred is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * Fivehundred is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * Fivehundred. If not, see <http://www.gnu.org/licenses/>. 
 */

package com.googlecode.fivehundred.svg;

import java.awt.Image;
import java.util.HashMap;
import java.util.Map;

import com.googlecode.fivehundred.model.CardRenderer;

// TODO merge into the dynamic card hierrarchy
public class DefaultCardBackRenderer implements CardRenderer {

	private static final String CARD_BACK_FILENAME = "card_back.svg";
	private static Map<String, Image> imageCache = new HashMap<String, Image>();
	private SVGRasterizer rasterizer = new SVGRasterizer();

	public Image getImage() {
		return getImage(DynamicCardRenderer.DEFAULT_WIDTH, DynamicCardRenderer.DEFAULT_HEIGHT);
	}

	public Image getImage(int width, int height) {
		String imageKey = CARD_BACK_FILENAME + "(" + width + "," + height + ")";
		Image image = imageCache.get(imageKey);
		if (image == null) {
			image = rasterizer.createImage(ClassLoader.getSystemResource(CARD_BACK_FILENAME), width);
			imageCache.put(imageKey, image);
		}
		return image;
	}

}
